<#include "head_bus.ftl">
<script>
window.onload=function(){
	$("title").html("我的业务-支付密码设置");
}
</script>
<!--内容开始-->
<div class="container">
    <ol class="breadcrumb">
      <li><a href="#">首页</a></li>
      <li><a href="#">个人中心</a></li>
      <li class="active">支付密码设置</li>
    </ol>
    <div class="p-content f18">
        <form class="form-horizontal f15" id="myForm" method="post">                  
           <div class="form-group">
              <label class="col-sm-6 col-xs-4 control-label">验  证  码：</label>
              <div class="col-sm-3  col-xs-4">
                 <input type="text" class="form-control" id="verify">
              </div>
              <a href="javascript:checking()" id="getVerify" class="btn btn-y btn-110 code">获取验证码</a>
              <a href="###" class="btn btn-c btn-110 code-1 d-none" id="reGetVerify">重新发送</a>
           </div>
           <div class="form-group">
              <label class="col-sm-6 col-xs-4 control-label">支付密码：</label>
              <div class="col-sm-5  col-xs-7">
                 <input type="password" class="form-control" id="newpassword" maxlength="6">
              </div>
           </div>  
            <div class="form-group">
              <label class="col-sm-6 col-xs-4 control-label">确认密码：</label>
              <div class="col-sm-5  col-xs-7">
                 <input type="password" class="form-control" id="repassword" maxlength="6">
              </div>
           </div>                  
            <div class="form-group">
              <div class="text-center">
                <div class="col-sm-5 col-sm-offset-6 col-xs-10 col-xs-offset-1">
                  <button type="button" class="btn btn-s btn-280" onclick="setPayPwd()">确            认</button>
                </div
              </div>
          </div>
          <input type="hidden" id="account" value="${userObj.reg_tel}" />                                
        </form>

    </div>
 
</div>


<!-- 弹出层 -->
<!-- 支付密码设置成功 -->
<div class="modal fade" id="modal-15">
    <div class="modal-dialog modal-400">
        <div class="modal-content">
           <div class="modal-header">
               <a class="close" data-dismiss="modal">×</a>   
           </div>
           <div class="modal-body text-center">
                <span class="glyphicon glyphicon-ok ok"></span><br/>
                <p class="h4 mt20">支付密码设置成功</p>
           </div>
        </div>
    </div>
</div>
<script>
/**发送验证码**/
		function checking(){
		    var account=$("#account").val();
		    var timeSms = getCookieValue("secondsremained");
		    if(timeSms>0){
		    	alert(timeSms+"秒后，请重新获取验证码!");
		    	time('getVerify','reGetVerify');
		    	return;
		    }
		    $.ajax({
		            cache: true,
		            type: "POST",
		            url:"${BASE_PATH}/user/verifyyzm.json",
		            data:{account:account,status:3},
		            async: true,
		            success: function(data){
		               if(data.status==1){//发送成功
		               		addCookie("secondsremained",60,60);//添加cookie记录,有效时间60s
				            alertMsgSuccess(data.info);
						}else if(data.status==2){//发送失败
							//time('getVerify','reGetVerify');
				            alertMsgError(data.info);
						}else{
							//time('getVerify','reGetVerify');
				            alertMsgError(data.info);
						}
		
						time('getVerify','reGetVerify');
		            }
		     });
		}

	//提交表单
	function setPayPwd(){
		var verify=$("#verify").val();
		if(''==verify){
			alertMsgError("验证码不能为空");
			return;
		}
		var newpassword=$("#newpassword").val();
		if(''==newpassword){
			alertMsgError("支付密码不能为空");
			return;
		}
		var repassword=$("#repassword").val();
		if(''==repassword){
			alertMsgError("确认密码不能为空");
			return;
		}
		
		
		//验证
		var array=[[/^[\d]{6}?$/,newpassword,"支付密码格式错误，请输入6位数字密码"]];
		for(var	 i=0;i<array.length	;i++)
		{
			if(array[i][0].test(array[i][1])==false)
			{
				alertMsgError("支付密码格式错误",array[i][2]);
				return;
			}
		}
		
		$.ajax({
		            cache: true,
		            type: "POST",
		            url:"${BASE_PATH}/user/setPayPwd.json",
		            data:{verify:verify,newpassword:newpassword,repassword:repassword},
		            async: true,
		            success: function(data){
		               if(data){//发送成功
		               		if(data.status==2){
		               			//alertMsgSuccess(data.info);
		               			alert("支付密码设置成功，点击确认后转到支付密码管理页面！");
		               			
		               			window.location.href="${BASE_PATH}/user/payPwdAdmin.htm";
		               		//	eachInputEmpty('myForm');
		               		//	$("#account").val('${userObj.reg_tel}');
		               		}else{
		               			alertMsgError(data.info);
		               		}
					   }
		            }
		     });
		
	}
	function cancleClose(modal){
		$("#"+modal+"").modal('hide');
		eachInputEmpty(modal);
	}
	var t=3;
	//失败-错误,弹窗
	function alertMsgError(title){
		$('#modal-15 p').each(function(index){
			if(index==0){
				$(this).html("<font>"+title+"</font><br><font id='overTime'></font>");
			}
		})
		$('#modal-15').modal('show');
		overTime(t,'modal-15');
	}
	//倒计时
	function overTime(t,modal){
		var str="";
		if(t==0){
			cancleClose(modal);
		}else{
			str="本窗口将在"+t+"秒后自动关闭";
			t--;
			$("#overTime").text("("+str+")");
			setTimeout(function(){
				overTime(t,modal);
			},1000);
		}
	}
	//成功弹窗
	function alertMsgSuccess(title){
		$('#modal-15 p').each(function(index){
			if(index==0){
				$(this).html("<font>"+title+"</font><br><font id='overTime'></font>");
			}
		})
		$('#modal-15').modal('show');
		overTime(t,'modal-15');
	}
	//清空input
	function eachInputEmpty(id){
		$("#"+id+" input").each(function(){
			$(this).val("");
		})
	}
</script>
<#include "foot_bus.ftl">